<?php 
define("UNDERKLEO", true);
require_once '../../../../conf/kleoconfig.php';
$criteria = $_POST['search']; 

$menu_query = $kleocore->query("SELECT * FROM ".KLEO_TABLE_PREFIX."menus_items WHERE MATCH(title,link) AGAINST ('%$criteria%' IN BOOLEAN MODE) ORDER BY title ASC");
while($row = $kleocore->fetch_array($menu_query)):
  $kleowidgets->compile($row['title'],$row['title']);
  $results[] = array($row['link'],$row['title'],'modules/admin/media/icons/8x8/link.gif');
endwhile;


$modules_query = $kleocore->query("SELECT * FROM ".KLEO_TABLE_PREFIX."modules WHERE MATCH(name) AGAINST ('%$criteria%' WITH QUERY EXPANSION) ORDER BY name ASC");
while($row = $kleocore->fetch_array($modules_query)):
  $results[] = array("?module=".$row['name'],$row['name'],'modules/admin/media/icons/8x8/crank.gif');
endwhile;

$users_query = $kleocore->query("SELECT * FROM ".KLEO_TABLE_PREFIX."users_profiles WHERE MATCH(nicename,bios) AGAINST ('%$criteria%' IN BOOLEAN MODE) OR nicename LIKE '%$criteria%'");
while($row = $kleocore->fetch_array($users_query)):
  $results[] = array("?module=users&uid=".$row['uid'], $row['nicename'],'modules/admin/media/icons/8x8/user.gif');
endwhile;

$blog_query = $kleocore->query("SELECT * FROM ".KLEO_TABLE_PREFIX."blog WHERE MATCH(title) AGAINST('%$criteria%' IN BOOLEAN MODE) OR title LIKE '%$criteria%'");
while($row = $kleocore->fetch_array($blog_query)):
  if(strlen($row['title']) > 32){
    $title = substr($row['title'],0,32).'...';
  } else {
    $title = $row['title'];
  }
  $results[] = array("?module=admin&file=newpost.tpl&id=".$row['id'], $title, null);
endwhile;

$menu_query = $kleocore->query("SELECT * FROM ".KLEO_TABLE_PREFIX."menus_items WHERE MATCH(title) AGAINST('%$criteria%' IN BOOLEAN MODE) OR title LIKE '%$criteria%'");
while($row = $kleocore->fetch_array($menu_query)):
  if(strlen($row['title']) > 32){
    $title = substr($row['title'],0,32).'...';
  } else {
    $title = $row['title'];
  }
  $this->compile($title,$item);
  $results[] = array($row['link'], $item, null);
endwhile;
?>

<ul>
<?php
  foreach($results as $result):
    echo '<li><a href="'.$result[0].'">'.$result[1].'<img align="top" src="'.$result[2].'" /></a><li>';
  endforeach;
?>
</ul>
